package com.bawei.bydayzg_two.viewModel

import androidx.lifecycle.viewModelScope
import com.bawei.base.bean.CartGoreyResult
import com.bawei.base.bean.GoodsResult
import com.bawei.base.bean.Res
import com.bawei.base.http.SingleLiveData
import com.bawei.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CartGroyViewModel:BaseViewModel() {

    //
    val cartGroySuccess = SingleLiveData<Res<CartGoreyResult>>()
    val cartGroyFail = SingleLiveData<String>()
    //
    fun cartGroy(){
        viewModelScope.launch {
            try {
                cartGroySuccess.postValue(apiService.cartGory())
            } catch (e: Exception) {
                cartGroyFail.postValue(e.message.toString())
            }
        }
    }

    //请求商品
    val goodsSuccess = SingleLiveData<Res<GoodsResult>>()
    val goodsFail = SingleLiveData<String>()
    //
    fun goods(cid:Int,
              keyword:String,
              limit:Int,
              news:Boolean,
              page:Int,
              priceOrder:String,
              salesOrder:String){
        viewModelScope.launch {
            try {
                goodsSuccess.postValue(apiService.goods(cid, keyword, limit, news, page, priceOrder, salesOrder))
            } catch (e: Exception) {
                goodsFail.postValue(e.message.toString())
            }
        }
    }
}